function matchPhoneType() {
	switch (uni.getSystemInfoSync().platform) {
		case 'android':
			console.log('运行Android上')
			return 1;
			break;
		case 'ios':
			console.log('运行iOS上')
			return 2;
			break;
		default:
			console.log('运行在开发者工具上')
			return 1;
			break;
	}
}

//统一获取系统信息
function uniqueGetSystemInfo() {
	var info = getApp().globalData.systemInfo
	if (info == null) {
		var res = uni.getSystemInfoSync() //同步获取
		getApp().globalData.systemInfo = res //App全局临时赋值
		return res
	} else {
		return info
	}
}


function getTopBarHeight(){
	let res = uniqueGetSystemInfo()
	let navbarHeight = (res.navigationBarHeight || res.titleBarHeight || 44)
	return res.statusBarHeight + navbarHeight
}


//校验手机是否合法
function isPhoneNumber(mobile) {
	var reg = /^[1][0-9]{10}$/
	if (mobile.length == 11 && reg.test(mobile)) {
		return true
	} else {
		return false
	}
}

function stringIsEmpty(data) {
	return data == undefined || data == null || data == ''
}
//字符串不为空
function stringNoEmpty(data) {
	let defaultData = arguments[1] || '';
	if (data == null || data == "" || data == "undefined") {
		return defaultData
	} else {
		return data
	}
}
//数字不为空
function numberNoEmpty(data) {
	let defaultData = 0
	if (data == null) {
		return defaultData
	} else {
		return data
	}
}
// 判断一个值是数字
function myIsNaN(value) {
	return typeof value === 'number' && !isNaN(value);
}

// 判断一个值是数字
function isNumbder(value) {
	if (value === "" || value == null) {
		return false;
	}
	if (!isNaN(value)) {
		//对于空数组和只有一个数值成员的数组或全是数字组成的字符串，isNaN返回false，例如：'123'、[]、[2]、['123'],isNaN返回false,
		//所以如果不需要value包含这些特殊情况，则这个判断改写为if(!isNaN(value) && typeof value === 'number' )
		return true;
	} else {
		return false;
	}
}

function showMyToast(content) {
	uni.showToast({
		title: content,
		icon: 'none',
		duration: 1000
	})
}

module.exports = {
	matchPhoneType: matchPhoneType,
	numberNoEmpty: numberNoEmpty,
	isNumbder: isNumbder,
	stringIsEmpty: stringIsEmpty,
	stringNoEmpty: stringNoEmpty,
	numberNoEmpty: numberNoEmpty,
	myIsNaN: myIsNaN,
	showMyToast: showMyToast,
	isPhoneNumber: isPhoneNumber,
	uniqueGetSystemInfo: uniqueGetSystemInfo,
	getTopBarHeight:getTopBarHeight,
	
	//微信的appId
	getWxAppid() {
		return uni.getStorageSync("weixinAppid") ? uni.getStorageSync("weixinAppid") : ''
	},
	//淘宝的appid
	getTaoBaoAppid() {
		return uni.getStorageSync("taobaoAppid") ? uni.getStorageSync("taobaoAppid") : ''
	},
	//淘宝的appid
	getTaoBaoKey() {
		return uni.getStorageSync("taobaoKey") ? uni.getStorageSync("taobaoKey") : ''
	},
	//淘宝的Secret
	getTaoBaoSecret() {
		return uni.getStorageSync("taobaoSecret") ? uni.getStorageSync("taobaoSecret") : ''
	},
	//淘宝h5授权地址
	getTaoBaoRedirect() {
		return uni.getStorageSync("taobaoUrl") ? uni.getStorageSync("taobaoUrl") :
			'https://www.gomyorder.cn/pages/member/publisher'
	},
	//好单库接口淘宝名 必须英文的 tb_name
	getTaoBaoName() {
		return uni.getStorageSync("taobaoName") ? uni.getStorageSync("taobaoName") : ''
	},
	//淘宝设置的PID
	getTaoBaoPid() {
		return uni.getStorageSync("taobaoPid") ? uni.getStorageSync("taobaoPid") : ''
	},
	//好单库Key
	getTaoBaoKey() {
		return uni.getStorageSync("haodankuKey") ? uni.getStorageSync("haodankuKey") : ''
	},
	//全局邀请码
	getInvitation() {
		return uni.getStorageSync("publicRelation") ? uni.getStorageSync("publicRelation") : ''
	},
	//获取拼多多商城地址
	getPingDuoDuo() {
		return uni.getStorageSync("pinduoduo") ? uni.getStorageSync("pinduoduo") :
			'https://mobile.yangkeduo.com/duo_cms_mall.html?pid=8948958_104234125&cpsSign=CM_190809_8948958_104234125_05e68780da621fd572b728c3ae1ee027&range_items=1%3A0%3A10000%2C2%3A10%3A1000&duoduo_type=2'
	},
	//获取拼多多默认地址
	getPingDuoDuoPid() {
		return uni.getStorageSync("pinduoduopid") ? uni.getStorageSync("pinduoduopid") : ''
	},
	//京东默认pid
	getJDPid() {
		return uni.getStorageSync("jingdongpid") ? uni.getStorageSync("jingdongpid") : ''
	},
	//获取APP下载地址
	getAppDownUrl() {
		return uni.getStorageSync("appurl") ? uni.getStorageSync("appurl") : ''
	},
	dateFormat(time) {
		console.log(time)
		let date = new Date(time);
		let year = date.getFullYear();
		// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
		let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
		let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
		let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
		let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
		let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
		// 拼接
		// return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
		return year + "-" + month + "-" + day;
	},
	
}
